package com.softserveinc.autorent.rest;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import com.softserveinc.autorent.controller.UserController;
import com.softserveinc.autorent.model.Car;
import com.softserveinc.autorent.model.User;
import com.softserveinc.autorent.model.UserDriveLicense;
import com.softserveinc.autorent.model.UserInfo;


@ManagedBean
@RequestScoped
public class UserMB {
	
	@EJB
	private UserController userController;

	private User user;
    private DataModel<User> userList;      
    
    public DataModel<User> getUserList() {

		 List<User> lista = userController.getAll();
		 userList = new ListDataModel<User>(lista);
         return userList;
         
    }

    public User getUser() {
        return user;
    }

    public void setUserr(User user) {
        this.user = user;
    }

    public String prepareAddUser(){
        user = new User();
        return "Create person";
    }
          

    public String prepareUpdateUser(){
        user = (User)(userList.getRowData());
        return "Create person";
    }

    public String deleteUser(){

    	User user = (User)(userList.getRowData());    	
    	userController.delete(user);
        return "index";

    }

    public String addUser(){    	
    	userController.create(user);
        return "index";
        
    }

    public String updateUsers(){    	
    	userController.update(user);
        return "index";

    }
}
